var sDate;
var eDate;
var SearchUserLog;
var session = sessionStorage.getItem("session");
$(document).ready(function() {

	if (!session) {
		window.parent.location = "../../login.html";
	}
	$('#sDateUserLog').datetimebox('setValue', ThreeDayBefore);
	BodyHeight = window.screen.height;
	BodyWidth = window.screen.width;
	sDate = $('#sDateUserLog').datetimebox('getValue').substr(0, 10);
	eDate = $('#eDateUserLog').datetimebox('getValue').substr(0, 10);
	var filter;
	jQuery("#UserLogGrid").jqGrid({
		url: IP + "GetUserLog?callback=?&session=" + session + "&sDate=" + sDate + "&eDate=" + sDate,
		datatype: "jsonp",
		colModel: [{
			label: '序号',
			sorttype: 'integer',
			name: 'id',
			sopt: ['eq'],
			key: true,
			width: 75
		}, {
			label: '操作时间',
			sopt: ['eq'],
			name: 'operationTime'
		}, {
			label: '登录名',
			sopt: ['eq'],
			name: 'loginName'
		}, {
			label: 'IP地址',
			sopt: ['eq'],
			name: 'ip',
			width: 150
		}, {
			label: '系统',
			sopt: ['eq'],
			name: 'system'
		}, {
			label: '模块',
			sopt: ['eq'],
			name: 'model'
		}, {
			label: '操作对象',
			sopt: ['eq'],
			name: 'operand'
		}, {
			label: '执行动作',
			sopt: ['eq'],
			name: 'action'
		}, {
			label: '原值',
			sopt: ['eq'],
			name: 'oldValue'
		}, {
			label: '新值',
			sopt: ['eq'],
			name: 'newValue'
		}],
		pagerpos: 'center',
		viewrecords: true,
		rowNum: 17,
		height: 470,
		autowidth: true,
		loadonce: true,
		page: 1,
		loadtext: '正在加载数据',
		pager: "#UserLogGridPager",
		sortorder: "asc",
		sortname: 'id'
	});

	$(window).bind('resize', function() {
		$("#UserLogGrid").setGridWidth($(window).width() * 1);
		$("#UserLogGrid").setGridHeight($(window).height() - 120);
	});

	ExportFile = function() {
		$('#UserLogGrid').jqGrid('setGridParam', {
			rowNum: 1000,
		}).trigger('reloadGrid');
		var title = "操作历史统计";
		getXlsFromTbl('UserLogGrid', 'gridtable', title, false);
		setTimeout(BackGrid(), 500);

		function BackGrid() {
			$('#UserLogGrid').jqGrid('setGridParam', {
				rowNum: 17,
			}).trigger('reloadGrid');
		}
	}

	SearchUserLog = function() {
			sDate = $('#sDateUserLog').datetimebox('getValue').substr(0, 10);
			eDate = $('#eDateUserLog').datetimebox('getValue').substr(0, 10);
			if (DateRight(sDate, eDate)) {
				var myurl = IP + "GetUserLog?callback=?&session=" + session + "&sDate=" + sDate + "&eDate=" + eDate;
				$('#UserLogGrid').jqGrid('setGridParam', {
					url: myurl,
					type: 'Get',
					datatype: "jsonp",
				}).trigger('reloadGrid');
				insertopertlog('系统管理', '操作历史查询', '查询', '', '');
				console.log(myurl);
			} else {
				$.messager.show({
					title: '提醒',
					msg: '请选择正确的时间范围！',
					timeout: 1300,
					showType: 'slide',
					style: {
						right: '',
						bottom: ''
					}
				});
			}
		}
		////--------------------------------------------tab按ID查询------------------------------------------------
	var timer;
	$("#UserLogKeyWord").on("keyup", function() {
		var self = this;
		if (timer) {
			clearTimeout(timer);
		}
		timer = setTimeout(function() {
			//timer = null;
			$("#UserLogGrid").jqGrid('filterInput', self.value);
		}, 0);
	});
})